Skip to content

Conversation

@ABesharat
Copy link
Contributor

This branch provides hardcoded biorthgonal and nns coefficients

…nal_coefficients' into azam/feature/hardcoded_biorthogonal_coefficients
…eature/hardcoded_biorthogonal_coefficients

# Conflicts:
#	SeQuant/domain/mbpt/biorthogonalization.cpp
@ABesharat ABesharat force-pushed the azam/feature/hardcoded_biorthogonal_coefficients branch from ae2bb57 to f8f3115 Compare January 18, 2026 23:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces hardcoded (exact) biorthogonalization coefficients and NNS projection weights to avoid numerical precision loss, and updates evaluation/tests to use the new NNS projection path.

Changes:

  • Add hardcoded biorthogonal coefficient generation (ranks 1–5) with memoization fallback to computed coefficients for higher ranks.
  • Introduce NNS projection weights (hardcoded up to rank 5, computed beyond) and TA/BTAS projection helpers.
  • Update spintracing normalization behavior and adjust evaluation unit tests accordingly.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
SeQuant/domain/mbpt/biorthogonalization.hpp Declares hardcoded coefficient APIs, adds NNS projector weights + TA/BTAS projection helpers.
SeQuant/domain/mbpt/biorthogonalization.cpp Implements hardcoded coefficient matrices, memoized coefficient selection, and computed NNS weights.
SeQuant/domain/mbpt/spin.cpp Simplifies S normalization factor handling in closed_shell_CC_spintrace_v2.
SeQuant/core/eval/result.hpp Removes Result-level NNS projection implementation (migrated out).
SeQuant/core/eval/eval.hpp Removes EvalMode::BiorthogonalNNSProject and evaluate_biorthogonal_nns_project.
tests/unit/test_eval_ta.cpp Updates TA evaluation to call the new NNS projection helper and adds rank-4 NNS test.
tests/unit/test_eval_btas.cpp Updates BTAS evaluation to call the new NNS projection helper and adjusts permutation averaging.
tests/unit/test_spin.cpp Updates comments/section naming reflecting new spintracing behavior.
CMakeLists.txt Adds compile definitions for evaluation-related feature macros.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +450 to +471
auto memoize = []<typename T>(container::map<std::pair<std::size_t, double>,
std::optional<T>>& cache,
std::mutex& mutex, std::condition_variable& cv,
std::pair<std::size_t, double> key,
auto compute_fn) -> const T& {
{
std::unique_lock<std::mutex> lock(mutex);
auto [it, inserted] = cache.try_emplace(key, std::nullopt);
if (!inserted) {
cv.wait(lock, [&] { return it->second.has_value(); });
return it->second.value();
}
}

T result = compute_fn();

{
std::lock_guard<std::mutex> lock(mutex);
cache[key] = std::move(result);
cv.notify_all();
return cache[key].value();
}
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local memoize helper can deadlock if compute_fn throws: the inserted cache entry stays std::nullopt and any concurrent callers will wait forever on the condition_variable. Add exception handling to ensure the cache is updated/erased and cv.notify_all() is called on failure.

Copilot uses AI. Check for mistakes.
Comment on lines 186 to 199
static std::mutex cache_mutex;
static std::condition_variable cache_cv;
static container::map<CacheKey, CacheValue> cache;

CacheKey key{n_particles, threshold};

{
std::unique_lock<std::mutex> lock(cache_mutex);
auto [it, inserted] = cache.try_emplace(key, std::nullopt);
if (!inserted) {
cache_cv.wait(lock, [&] { return it->second.has_value(); });
return it->second.value();
}
}
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nns_projection_weights memoization can deadlock: if computing coefficients throws, the cache entry remains std::nullopt and any waiting threads will block forever. Consider storing an exception state (e.g., std::exception_ptr) or erasing the key and notifying in a catch block so waiters don’t hang.

Copilot uses AI. Check for mistakes.
@evaleev evaleev merged commit 8bf20b9 into master Jan 24, 2026
16 checks passed
@evaleev evaleev deleted the azam/feature/hardcoded_biorthogonal_coefficients branch January 24, 2026 01:25
evaleev added a commit that referenced this pull request Jan 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants